<template>
    <div>{{ str[index] }}</div>
    <button @click="start" :disabled="isDisabled">开始</button>
    <button @click="stop">结束</button>
</template>

<script setup>
import { ref } from 'vue'
const str = ref([1,2,3,4,5])
const index = ref(-1)
const isDisabled = ref(false)
let timer;
const start = () => {
    isDisabled.value = true
    timer = setInterval(() => {
       index.value = parseInt(str.value.length * Math.random())
    },100)
}
const stop = () => {
    isDisabled.value = false
    clearInterval(timer)
}

</script>

<style scoped>

</style>